package com.wsc.wsckeeper.listeners;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.support.v4.view.ViewPager;

import com.wsc.wsckeeper.R;
import com.wsc.wsckeeper.activities.BaseTabActivity;

public class TabsListener implements ActionBar.TabListener {
	private ActionBar actionbar;
	private Activity activity;
	private ViewPager mViewPager;

	public TabsListener(ActionBar actionbar, Activity activity, ViewPager mViewPager) {
		this.actionbar = actionbar;
		this.activity = activity;
		this.mViewPager = mViewPager;
	}

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		int i = tab.getPosition();
		mViewPager.setCurrentItem(i);
		switch (i) {
		case BaseTabActivity.CARDS_TAB:
			actionbar.setSubtitle(R.string.action_list_cards);
			break;
		case BaseTabActivity.ACCOUNTS_TAB:
			actionbar.setSubtitle(R.string.action_list_accounts);
			break;
		}
		activity.invalidateOptionsMenu();
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
	}
}
